//
//  CHInformDetailController.m
//  CarFile
//
//  Created by 陈浩 on 2017/8/3.
//  Copyright © 2017年 陈浩. All rights reserved.
//

#import "CHInformDetailController.h"

@interface CHInformDetailController ()<UIWebViewDelegate>
@property (nonatomic ,strong) UIWebView *myWebView;
@end

@implementation CHInformDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"通知详情";
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self setupUI];
    
}

-(void)setupUI{
    
    CGSize maxSize = CGSizeMake(UIScreenW -2*15, MAXFLOAT);
    NSDictionary *attr = @{NSFontAttributeName:[UIFont systemFontOfSize:15]};
    CGSize titleSize = [self boundingRectWithSize:maxSize attributes:attr text:self.model.title];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 15, UIScreenW - 30, titleSize.height)];
    titleLabel.text = self.model.title;
    titleLabel.numberOfLines = 0;
    titleLabel.font = [UIFont boldSystemFontOfSize:15];
    [self.view addSubview:titleLabel];
    
    
    UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(UIScreenW - 100 - 15, CGRectGetMaxY(titleLabel.frame) , 100, 30)];
    timeLabel.font = [UIFont systemFontOfSize:12];
    timeLabel.textAlignment = NSTextAlignmentRight;
    timeLabel.text = [self.model.publishtime substringToIndex:11];
    timeLabel.textColor = [UIColor colorWithHexString:@"999999" alpha:0.7];
    [self.view addSubview:timeLabel];
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(timeLabel.frame) +5, UIScreenW - 30, 1)];
    line.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:line];
    
    
    
    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(line.frame), UIScreenW, UIScreenH - CGRectGetMaxY(line.frame) - 64)];
    webView.delegate = self;
//    [webView setScalesPageToFit:YES];
    [self.view addSubview:webView];
    
    [webView loadHTMLString:self.model.content baseURL:nil];
    
    
    
}


//- (void)back:(UIBarButtonItem *)btn
//{
//    if ([self.webView canGoBack]) {
//        [self.webView goBack];
//        
//    }else{
//        [self.view resignFirstResponder];
//        [self.navigationController popViewControllerAnimated:YES];
//    }
//}


- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSLog(@"%f",webView.frame.size.height);
}


- (CGSize)boundingRectWithSize:(CGSize)maxSize attributes:(NSDictionary *)attr text:(NSString *)text
{
    return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attr context:nil].size;
}

#pragma mark LongriseRouterDelegater代理回调方法
-(void)setParams:(id)obj block:(LongriseRouterBlock)block
{
    
    if (obj && [obj isKindOfClass:[NSMutableDictionary class]]) {
        
        NSMutableDictionary *dict = obj;
        self.model = dict[@"model"];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
